<?php
/*
 *   This file is part of poat.
 *
 *   poat2 is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   poat2 is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with poat2.  If not, see <http://www.gnu.org/licenses/>.
 *   
 *   Copyright (c) 2008 Sergio Gabriel Teves <gabriel.sgt at gmail.com>
 * */
 
include_once(ROOT_PATH."includes/common.php");
require_once(ROOT_PATH."class/user.class.php");
require_once(ROOT_PATH."class/history.class.php");
require_once(ROOT_PATH."class/files.class.php");
require_once(ROOT_PATH."class/project.class.php");
include_once(ROOT_PATH."includes/currentuser.php");

if ($op=="add") {
	$prj = new project;
	$prj->id=$data['add_file_subprj'];
	$loader->get($prj);
	
	$file = new files($data['add_file_prj']);
	$file->teamid=$data['add_file_teamid'];
	$file->name=$data['add_file_name'];
	$file->path=$prj->name;
	$file->subprj=$prj->id;
	
	if ($loader->save($file)>=0) {
		$message = "Added file ".$file->name;	
	} else {
		$error = "Error [$db->errno] $db->error"; 
	}
} else {
	$file = new files($prj);
	$file->id=$id;
	$loader->get($file);
			
	$h = new history($prj);
	$h->fileid=$id;
	if ($loader->delete($h)>=0) {
		if ($loader->delete($file)>=0) {
			$content = "File ".$file->name." removed!";
		} else {
			$content = "Error removing file ".$file->name;
		}	
	} else {
		$content = "Error removing history for file ".$file->name;
	}
}
?>
